package channelScheduler

import (
	"gitee.com/fierce_wolf/go-fox-edge-channel-common/channelAPI"
	"gitee.com/fierce_wolf/go-fox-edge-common/commEntityManager"
	"gitee.com/fierce_wolf/go-fox-edge-common/commRedisRpc"
	"time"
)

type channelReportToScheduler struct {
}

// Scheduler 创建一个线程
func (e *channelReportToScheduler) Scheduler() {
	go e.scheduler()
}

// 线程函数
func (e *channelReportToScheduler) scheduler() {
	for true {
		time.Sleep(50 * time.Millisecond)

		if !commEntityManager.EntityManager.Initialized || channelAPI.Service.IReport == nil {
			time.Sleep(1 * time.Second)
			continue
		}

		respondVOS, err := channelAPI.Service.GetReports()
		if err != nil || len(respondVOS) == 0 {
			continue
		}

		// 处理数据
		for _, respondVO := range respondVOS {
			respondVO.Mode = "receive"
			err := commRedisRpc.Channel.Server.Report.Push(respondVO)
			if err != nil {
				continue
			}
		}

	}
}
